package cn.yangliu.jwt.comm;

import lombok.Data;
import org.springframework.http.HttpStatus;

/**
 * @author 杨柳
 * @date 2019-04-18
 */
@Data
public class JsonResult<T extends Object> {
    private Integer code;
    private String msg;
    private T data;

    private JsonResult(T data) {
        this.data = data;
        this.code = HttpStatus.OK.value();
    }

    public JsonResult(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public JsonResult(HttpStatus status, String msg) {
        this(status.value(), msg);
    }

    public JsonResult(Integer code, String msg, T data) {
        this(data);
        this.msg = msg;
        this.code = code;
    }

    public JsonResult(HttpStatus status, String msg, T data) {
        this(status.value(), msg, data);
    }


    public static <T> JsonResult<T> getInstance(T data) {
        return new JsonResult<>(data);
    }

    public static <T> JsonResult<T> getInstance() {
        return new JsonResult<>(null);
    }

}
